//
// 继承
//
class Animal {
  public name: string;
  private type: string;
  constructor(name: string, type: string) {
    this.name = name;
    this.type = type;
  }
  eat(food: string): void {
    console.log(this.name, "Eating", food);
  }
  say(): void {
    console.log(this.name, "say");
  }
}
class Dog extends Animal {
  say(text?: string): void {
    text = "Woof!";
    console.log(this.name, "say", text);
  }
}
class People {
  readonly _type = "people";
  // name 是参数属性，和 Animal 中的 name 作用相同
  constructor(public name: string) {}
  eat(food: string): void {
    console.log(this.name, "Eating", food);
  }
  say(text: string): void {
    console.log(this.name, "say", text);
  }
  get type(): string {
    return this._type;
  }
}
const dog1 = new Dog("dog1", "dog");
dog1.eat("apple");
dog1.say();
const people1 = new People("people1");
people1.eat("banana");
people1.say("yes");
console.log("people1 is a", people1.type);
// 因为 private 属性不兼容，所以下面的两个对象不兼容
//let dog2 = new Dog("dog2", "dog");
//dog2 = new People("people2");

export {};
